package bigdata.api.weather.service.impl;

import bigdata.api.weather.service.WeatherService;
import datacenterbizapiexternal.weather.dao.mongodb.repositories.BaiduWeatherResponseParamsRepository;
import datacenterbizapiexternal.weather.domain.BaiduWeatherResponseParams;
import framework.util.date.DateStyle;
import framework.util.date.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 描述:
 *
 * @author 002465
 * @created 2017/6/7 21:30
 * @return ${return_type}
 * @since v1.0.0
 * ${tags}
 */
@Service
public class WeatherServiceImpl implements WeatherService {
    @Autowired
    private BaiduWeatherResponseParamsRepository repository;

    public BaiduWeatherResponseParams getGuanlingWeather(Date date){
        String currentCity = "关岭";
        return getCurrentCityWeather(currentCity,date);
    }

    public BaiduWeatherResponseParams getAnshunWeather(Date date){
        String currentCity = "安顺";
        return getCurrentCityWeather(currentCity,date);
    }

    public BaiduWeatherResponseParams getCurrentCityWeather(String currentCity,Date date){
        String dateStr = DateUtil.DateToString(new Date(), DateStyle.YYYY_MM_DD);
        List<BaiduWeatherResponseParams> list = repository.findByDate(dateStr);
        for (BaiduWeatherResponseParams data:list){
            if(data.getResults().get(0).getCurrentCity().equals(currentCity)){
                return  data;
            }
        }
        return null;
    }

}
